import request from '@/utils/request'
import request2 from '@/utils/request/index2.js'
import requestUser from '@/utils/request/index4.js'
// api地址
const api = {
  login: 'oauth/token',
  home: 'home/token/list',
  device: 'device/user',
  deviceType: 'device/type',
  loginMpWx: 'passport/loginMpWx',
  loginMpWxMobile: 'passport/loginMpWxMobile',
  isPersonalMpweixin: 'passport/isPersonalMpweixin',
  register: "user/register",
  getPhoneCode: "account/phoneCode",
  homeList: "home2/home/list",
  homeMembers: "home2/home/members",
  //用户报警设置
  alarm: "user/alarm",
}

// 用户登录 (手机号+验证码)
export function login(data) {
  return requestUser.post(api.login, data,{header: {
        'content-type': 'application/x-www-form-urlencoded',
    }})
}
//用户报警设置
export function getalarm(data) {
  return requestUser.get(api.alarm, data,{header: {
        'content-type': 'application/x-www-form-urlencoded',
    }})
}
export function postalarm(data) {
  return requestUser.post(api.alarm, data)
}

export function home(data) {
  return request2.get(api.home, data,{header: {
        'content-type': 'application/x-www-form-urlencoded',
    }})
}
export function homeList(data) {
  return request2.get(api.homeList, data,{header: {
        'content-type': 'application/x-www-form-urlencoded',
    }})
}
export function homeMembers(data) {
  return request2.get(api.homeMembers, data,{header: {
        'content-type': 'application/x-www-form-urlencoded',
    }})
}
export function device(data) {
  return request2.get(api.device, data,{header: {
        'content-type': 'application/x-www-form-urlencoded',
    }})
}
export function bindDevice(data) {
  return request2.put(api.device, data,{header: {
      'content-type': 'application/x-www-form-urlencoded',
    }})
}
export function getDeviceType() {
  return request2.get(api.deviceType)
}
// 微信小程序快捷登录 (获取微信用户基本信息)
export function loginMpWx(data, option) {
  return request.post(api.loginMpWx, data, option)
}

// 是否需要填写昵称头像 (微信小程序端)
export function isPersonalMpweixin(data, option) {
  return request.post(api.isPersonalMpweixin, data, option)
}

// 微信小程序快捷登录 (授权手机号)
export function loginMpWxMobile(data, option) {
  return request.post(api.loginMpWxMobile, data, option)
}

// 注册
export function register(data) {
  return requestUser.post(api.register, data,{header: {
      'content-type': 'application/x-www-form-urlencoded',
    }})
}

// 获取手机验证码
export const getPhoneCode = (data) => {
    return requestUser.get(api.getPhoneCode, data,{header: {
            'content-type': 'application/x-www-form-urlencoded',
        }})
}
